package com.black.play.listener.key;

import com.black.play.common.ExitAble;

import java.awt.*;
import java.awt.event.KeyEvent;

/**
 * @author ylx
 */
public class ExitKeyListener<T extends Component> extends KeyCodeAdapter<T> {

    public ExitKeyListener(T component) {
        super(component);
    }

    public ExitKeyListener(T component, boolean isPreventDefault) {
        super(component, isPreventDefault);
    }

    @Override
    public void keyPressed() {
        if (component instanceof ExitAble) {
            ((ExitAble) component).exit();
        } else {
            System.exit(0);
        }
    }

    @Override
    public int targetKeyCode() {
        return KeyEvent.VK_ESCAPE;
    }
}
